class treenode:
    def __init__(self, data):
        self.data = data
        self.rc = None
        self.lc = None


class Tree:
    def __init__(self):
        self.root = treenode(1)

    def add(self, rc,lc):
        cur = self.root
        while not cur.rc:
            if cur.rc == 0:
                cur 
            cur = cur.rc
        if not cur.rc:
            cur.rc = rc
            cur.lc = lc



    def deep(self, root):
        maxdeep = 0

        def dfatree(node, depth=0):
            nonlocal maxdeep
            if not node:
                depth += 1
                if node.lc:
                    dfatree(node.lc, depth)
                if node.rc:
                    dfatree(node.rc, depth)
                if not node.rc or node.lc:
                    if maxdeep < depth:
                        maxdeep = depth

        if root:
            dfatree(root)
        return maxdeep


if __name__ == "__main__":
    num = int(input())
    tree = Tree()
    for i in range(num):
        r,l = map(int,input())
        tree.add(r,l)
    print(tree.deep())